home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Procedure for initializing option file *)
- (* *)
- (* Copyright 1988, 1989, 1991 by H. Roy Engehausen. All rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$UNDEF DEBUG_OPT1} (* Port semaphore numbers *)
- {$UNDEF DEBUG_OPT2} (* Track progress *)
-
- PROCEDURE option_init;
-
- {$I BBOTYPE.PAS}
-
- VAR
- c_list_size : WORD;
- i : BYTE;
- in_file : file_name_str;
- j : WORD;
- last_port : port_block_ptr;
- look_port : port_block_ptr;
- opt_buffer : ^opt_file_rec;
- opt_file : FILE OF opt_file_rec;
- scb : str_chain_ptr;
- sema_num : BYTE;
- this_fd : fsb_ptr;
-
- BEGIN;
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Start option load');
- DELAY(300);
- {$ENDIF}
-
- in_file := PARAMSTR(1);
-
- IF in_file = '' THEN
- in_file := 'BBOPT.BB';
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Assign option');
- DELAY(300);
- {$ENDIF}
-
- ASSIGN(opt_file, in_file);
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Open option');
- DELAY(300);
- {$ENDIF}
-
- {$I-}
- RESET(opt_file);
- {$I+}
- IF IORESULT <> 0 THEN
- BEGIN;
- WRITELN(' ');
- WRITELN('Can''t open ', in_file, '. Has BBSETUP been run OK?');
- WRITELN('You must have successfully run BBSETUP to create the');
- WRITELN(in_file);
- WRITELN(' ');
- HALT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Allocate buffer *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Allocate buffer');
- DELAY(300);
- {$ENDIF}
-
-
- NEW(opt_buffer);
-
- (*-----------------------------------------------------------------------*)
- (* Read option block *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Read main block');
- DELAY(300);
- {$ENDIF}
-
- READ(opt_file, opt_buffer^);
- opt_block := opt_buffer^.opt_block_file;
-
- (*-----------------------------------------------------------------------*)
- (* Verify option block *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Verify main block');
- DELAY(300);
- {$ENDIF}
-
- WITH opt_block DO
- IF parm_file_ver <> this_bbs_parms THEN
- BEGIN;
- WRITELN;
- WRITELN('Incorrect version of the PARMS.BB has been found.');
- WRITELN('Expected ', this_bbs_parms,
- ' but got ', parm_file_ver, '.');
- WRITELN('Rerun the proper version of BBSETUP that matches this program');
- WRITELN;
- WRITELN;
- HALT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Read port blocks *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Start port loop');
- DELAY(300);
- {$ENDIF}
-
- ring_port := NIL;
-
- sema_num := semaphore_port_start;
-
- i := opt_block.port_count;
-
- WHILE i > 0 DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Read a block *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Read port blk');
- DELAY(300);
- {$ENDIF}
-
- DEC(i);
-
- READ(opt_file, opt_buffer^);
-
- (*-------------------------------------------------------------------*)
- (* Allocate space and copy it over *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Allocate port');
- DELAY(300);
- {$ENDIF}
-
- NEW(active_port);
-
- active_port^ := opt_buffer^.opt_port_file;
-
- (*-------------------------------------------------------------------*)
- (* Chain the port in *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Chain port');
- DELAY(300);
- {$ENDIF}
-
- IF ring_port = NIL THEN
- ring_port := active_port
- ELSE
- last_port^.next_port := active_port;
-
- last_port := active_port;
-
- (*-------------------------------------------------------------------*)
- (* Set the main port *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Main port');
- DELAY(300);
- {$ENDIF}
-
- active_port^.main_port := active_port;
- active_port^.next_port := NIL;
- active_port^.rel_port := NIL;
-
- (*-------------------------------------------------------------------*)
- (* See if this is a PCPA or BPQ subport. If so, connect things *)
- (* together *)
- (*-------------------------------------------------------------------*)
-
- WITH active_port^ DO
- IF (port_type = port_pcpa) OR (port_type = port_bpqhost) THEN
- BEGIN;
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('PCPA/BPQ port');
- DELAY(300);
- {$ENDIF}
-
- look_port := ring_port;
-
- WHILE (look_port <> NIL) AND (look_port <> active_port) DO
- IF look_port^.com_number = com_number THEN
- BEGIN;
- port_sub_port := TRUE;
- main_port := look_port^.main_port;
- rel_port := look_port^.rel_port;
- look_port^.rel_port := active_port;
- connected := look_port^.connected;
- look_port := NIL;
-
- END
- ELSE
- look_port := look_port^.next_port;
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Allocate the connected array. If a sub port, use the master *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Connected array');
- DELAY(300);
- {$ENDIF}
-
- WITH active_port^ DO
- IF NOT port_sub_port THEN
- BEGIN;
- c_list_size := (max_chan + 2) * SIZEOF(active_tcb);
- GETMEM(connected, c_list_size);
- FILLCHAR(connected^, c_list_size, #0);
- END
- ELSE
- connected := main_port^.connected;
-
- (*-------------------------------------------------------------------*)
- (* Assign a semaphore number to it. If sub-port, use the master *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Semaphore number');
- DELAY(300);
- {$ENDIF}
-
- WITH active_port^ DO
- IF port_sub_port THEN
- port_sema := main_port^.port_sema
- ELSE
- BEGIN;
- IF port_sema = 0 THEN
- BEGIN;
- port_sema := sema_num;
- INC(sema_num);
- END
- ELSE
- END;
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Port define -- ', active_port^.port_char,
- ' -- ', active_port^.port_num,
- ' -- ', active_port^.port_sub_port);
- DELAY(1000);
- {$ENDIF}
-
- END; (*----- End port read loop ---------------------------------------*)
-
- (*-----------------------------------------------------------------------*)
- (* Save highest semaphore number *)
- (*-----------------------------------------------------------------------*)
-
- high_semaphore := sema_num - 1;
-
- (*-----------------------------------------------------------------------*)
- (* Now complete the chain to give us a loop *)
- (*-----------------------------------------------------------------------*)
-
- last_port^.next_port := ring_port;
-
- (*-------------------------------------------------------------------------*)
- (* Create dummy port for the operator/forward tcbs *)
- (*-------------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('dummy port');
- DELAY(300);
- {$ENDIF}
-
- FILLCHAR(dummy_port, SIZEOF(dummy_port), #0);
-
- WITH dummy_port DO
- BEGIN;
- next_port := NIL;
- main_port := @dummy_port;
- rel_port := NIL;
- port_type := port_console;
- com_number := 0;
- port_char := 'L';
- max_pac := 80;
- data_rate := 0;
- max_conn := 1;
- max_chan := 2;
- port_pend := 100;
- call_set := '';
- port_color := default_data_color;
- c_list_size := (max_chan + 2) * SIZEOF(active_tcb);
- GETMEM(connected, c_list_size);
- FILLCHAR(connected^, c_list_size, #0);
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Initialize the watch blocks *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Watch block dummy');
- DELAY(300);
- {$ENDIF}
-
- j := opt_block.n_mon * SIZEOF(port_call_item);
-
- IF j = 0 THEN
- j := SIZEOF(port_call_item);
-
- WITH dummy_port DO
- BEGIN;
- GETMEM(call_list, j);
- FILLCHAR(call_list^, j, CHR(0));
- END;
-
- active_port := ring_port;
-
- REPEAT
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Watch block loop');
- DELAY(300);
- {$ENDIF}
-
- WITH active_port^ DO
- BEGIN;
- GETMEM(call_list, j);
- FILLCHAR(call_list^, j, CHR(0));
- active_port := next_port;
- END;
-
- UNTIL active_port = ring_port;
-
- (*-----------------------------------------------------------------------*)
- (* Read file block *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('File blocks');
- DELAY(300);
- {$ENDIF}
-
- i := opt_block.fd_count;
- fsb_base := NIL;
-
- WHILE i > 0 DO
- BEGIN;
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('File block loop');
- DELAY(300);
- {$ENDIF}
-
- DEC(i);
-
- READ(opt_file, opt_buffer^);
-
- NEW(this_fd);
-
- this_fd^ := opt_buffer^.opt_fd_file;
-
- this_fd^.next_fsb := fsb_base;
- fsb_base := this_fd
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Done with options file *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Close option');
- DELAY(300);
- {$ENDIF}
-
- CLOSE(opt_file);
-
- (*-----------------------------------------------------------------------*)
- (* Drop buffer *)
- (*-----------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Drop buffer');
- DELAY(300);
- {$ENDIF}
-
- DISPOSE(opt_buffer);
-
- {$IFDEF DEBUG_OPT2}
- WRITELN('Option done');
- DELAY(300);
- {$ENDIF}
-
- END;